<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="套压(MPa)" prop="taoYa">
				<u-input :border="border" placeholder="请输入套压" v-model="model.taoYa" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="含水比例(%)" prop="hanShui">
				<u-input :border="border" placeholder="请输入含水比例" v-model="model.hanShui" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="原油密度(g/cm³)" prop="youMi">
				<u-input :border="border" placeholder="请输入原油密度" v-model="model.youMi" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="地层水密度(g/cm³)" prop="diCengShui">
				<u-input :border="border" placeholder="请输入地层水密度" v-model="model.diCengShui" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="混合液深度(m)" prop="hunHeYe">
				<u-input :border="border" placeholder="请输入混合液深度" v-model="model.hunHeYe" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="当前井底流压" prop="jingDiLiuYa">
					<span v-if="model.jingDiLiuYa"> {{model.jingDiLiuYa}} MPa </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">当前井底流压= 套压+混合液柱压力(静液柱)</view>
				<view class="u-item-desc">混合液密度=原油密度 × (1-含水)+ 含水 × 地层水密度(取1.1)</view>
				<view class="u-item-desc">当前井底流压= 套压+混合液柱压力(静液柱)</view>
				<view class="u-item-desc">注：套压：MPa；密度："g/cm³"；混合液深度：m，沉没度；g：0.01</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					taoYa: '',
					hanShui: '',
					youMi: '',
					diCengShui: '1.1',
					hunHeYe: '',
					jingDiLiuYa: ''
				},
				rules: {
					taoYa: [{
						required: true,
						message: '请输入套压',
						trigger: 'blur'
					}],
					hanShui: [{
						required: true,
						message: '请输入含水比例',
						trigger: 'blur'
					}],
					youMi: [{
						required: true,
						message: '请输入原油密度',
						trigger: 'blur'
					}],
					hunHeYe: [{
						required: true,
						message: '请输入混合液深度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						// 计算混合液密度
						const hunHeYeMiDu = (parseFloat(this.model.youMi) * (1 - parseFloat(this.model.hanShui) / 100) + 
							parseFloat(this.model.hanShui) / 100 * parseFloat(this.model.diCengShui));
						
						// 计算当前井底流压
						this.model.jingDiLiuYa = (parseFloat(this.model.taoYa) + 
							parseFloat(hunHeYeMiDu) * 0.01 * parseFloat(this.model.hunHeYe)).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>